package com.bawei.test.banner

import android.view.RoundedCorner
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.youth.banner.adapter.BannerAdapter


/**
 * @Author : yaotianxue
 * @Time : On 2023/5/30 16:22
 * @Description : BannerAdapter
 */
class CustomBannerAdapter(var list:List<String>):BannerAdapter<String,CustomBannerAdapter.BannerViewHolder>(list) {

    class BannerViewHolder(var imageView: ImageView) : RecyclerView.ViewHolder(imageView)
    //创建viewholer
    override fun onCreateHolder(parent: ViewGroup, viewType: Int): BannerViewHolder {
        var imageView = ImageView(parent.context)
        imageView.layoutParams = ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT)
        imageView.scaleType = ImageView.ScaleType.FIT_XY
        return BannerViewHolder(imageView)
    }
    //绑定数据
    override fun onBindView(holder: BannerViewHolder, data: String, position: Int, size: Int) {
        Glide.with(holder.itemView)
            .load(data)
            .transform(CenterCrop(),RoundedCorners(30))
            .into(holder.imageView)
    }
}